package com.yfz.day08;

/**
 *  34 在排序数组中查找元素的第一个和最后一个位置
 */
class Solution {


    int findNum(int [] nums, int target){
        int start = 0 ;
        int end = nums.length - 1; // [start,end]
        while(start<=end){
            int mid = start + (end - start) / 2;
            if(nums[mid]< target) start = mid +1;
            else end = mid - 1;
        }
        return start;
    }

    public int[] searchRange(int[] nums, int target) {
        int left = findNum(nums,target);
        if(left == nums.length || nums[left] != target){
            return  new int[]{-1,-1};
        }
        int right = findNum(nums,target+1)-1;
        return new int[]{left,right};
    }
}